import request from '@/utils/request'
import * as x3 from "@/utils/x3request";
const publicNmae="GESITM2"

// 查询经销商列表
export function listGesitm2(query) {
  // console.log(query)
  var objectKeys=""
  Object.keys(query).forEach(function(key) {
    console.log(key + ': ' + query[key]);
    if(query[key]!=null && !['pageNum','pageSize'].includes(key)){
      objectKeys+="<key>"+key+"</key>"
      objectKeys+="<value>"
      if(['DES','YSQSJ','YBZ'].includes(key)){
        objectKeys+="*"+query[key]+"*"
      }else{
        objectKeys+=""+query[key]+""
      }
      objectKeys+="</value>"
    }
  });

  return x3.query(publicNmae,objectKeys,query.pageSize)
}

// 查询经销商详细
export function getGesitm2(ITMREF) {
  return x3.read(publicNmae,"<key>ITMREF</key>" +
    "<value>"+ITMREF+"</value>")
}

// 新增经销商
export function addGesitm2(data) {
  var obj=JSON.parse(JSON.stringify(data))
  obj.TSICOD[0]=data.TSICOD1
  obj.TSICOD[1]=data.TSICOD2
  delete obj.TSICOD1
  delete obj.TSICOD2
  delete obj.YFILE1
  delete obj.YFILE2
  delete obj.YCYYC
  delete obj.detail
  var objectXml={"HEAD":obj,"DETAIL":data.detail}
  return x3.save(publicNmae,objectXml)
}

// 修改经销商
export function updateGesitm2(data) {
  console.log(data)
  var obj=JSON.parse(JSON.stringify(data))
  obj.TSICOD[0]=data.TSICOD1
  obj.TSICOD[1]=data.TSICOD2
  delete obj.TSICOD1
  delete obj.TSICOD2
  delete obj.YFILE1
  delete obj.YFILE2
  delete obj.YCYYC
  delete obj.detail
  var objectXml={"HEAD":obj,"DETAIL":data.detail}
  console.log(objectXml)
  return x3.modify(publicNmae,"<key>ITMREF</key>" +
    "<value>"+data.ITMREF+"</value>",objectXml)
}

// 删除经销商
export function delGesitm2(ITMREF) {
  return x3.del(publicNmae,"<key>ITMREF</key>" +
    "<value>"+ITMREF+"</value>")
}

// 按钮操作
export function actionGesitm2(data,code) {
  return x3.actionObject(publicNmae,{"HEAD":data},code)
}
